/*     */ package com.zimbra.cs.mailbox.calendar;
/*     */ 
/*     */ import com.zimbra.common.calendar.ZCalendar.ICalTok;
/*     */ import com.zimbra.common.calendar.ZCalendar.ZVCalendar;
/*     */ import java.io.ByteArrayInputStream;
/*     */ import java.io.ByteArrayOutputStream;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStream;
/*     */ import java.io.OutputStream;
/*     */ import java.io.OutputStreamWriter;
/*     */ import javax.activation.DataSource;
/*     */ import javax.mail.internet.ContentType;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class CalendarDataSource
/*     */   implements DataSource
/*     */ {
/*     */   private ZCalendar.ZVCalendar mICal;
/*     */   private String mMethod;
/*     */   private String mAttachName;
/*  49 */   private byte[] mBuf = null;
/*     */   
/*     */   public CalendarDataSource(ZCalendar.ZVCalendar iCal, String attachmentName) {
/*  52 */     this.mICal = iCal;
/*  53 */     this.mAttachName = attachmentName;
/*  54 */     if ((this.mAttachName == null) || (this.mAttachName.equals(""))) {
/*  55 */       this.mAttachName = "meeting.ics";
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*  60 */     this.mMethod = iCal.getPropVal(ZCalendar.ICalTok.METHOD, ZCalendar.ICalTok.PUBLISH.toString());
/*     */   }
/*     */   
/*     */   public String getContentType() {
/*  64 */     ContentType ct = new ContentType();
/*  65 */     ct.setParameter("charset", "utf-8");
/*     */     
/*  67 */     ct.setPrimaryType("text");
/*  68 */     ct.setSubType("calendar");
/*  69 */     ct.setParameter("method", this.mMethod);
/*  70 */     if (!this.mAttachName.toLowerCase().endsWith(".ics")) {
/*  71 */       this.mAttachName += ".ics";
/*     */     }
/*  73 */     ct.setParameter("name", this.mAttachName);
/*     */     
/*  75 */     return ct.toString();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public InputStream getInputStream()
/*     */     throws IOException
/*     */   {
/*  86 */     synchronized (this) {
/*  87 */       if (this.mBuf == null) {
/*  88 */         ByteArrayOutputStream buf = new ByteArrayOutputStream();
/*  89 */         OutputStreamWriter wout = new OutputStreamWriter(buf, "utf-8");
/*     */         
/*  91 */         this.mICal.toICalendar(wout);
/*  92 */         wout.flush();
/*  93 */         this.mBuf = buf.toByteArray();
/*     */       }
/*     */     }
/*  96 */     ByteArrayInputStream in = new ByteArrayInputStream(this.mBuf);
/*  97 */     return in;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public String getName()
/*     */   {
/* 108 */     return null;
/*     */   }
/*     */   
/*     */ 
/*     */   public OutputStream getOutputStream()
/*     */     throws IOException
/*     */   {
/* 115 */     throw new UnsupportedOperationException();
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailbox/calendar/CalendarDataSource.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */